package controller

import (
	"base/app/models"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

type ShipCtl struct {
	db *gorm.DB
}

var Ship = ShipCtl{}

// 获取所有BargeShip
func (s *ShipCtl) GetBargeShip(c *gin.Context) {
	s.db = models.Db
	var bargeShip []models.BargeShip
	s.db.Find(&bargeShip)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "获取成功",
		"data": bargeShip,
	})
}

// 获取所有FisherShip
func (s *ShipCtl) GetFisherShip(c *gin.Context) {
	s.db = models.Db
	var fisherShip []models.FisherShip
	s.db.Find(&fisherShip)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "获取成功",
		"data": fisherShip,
	})
}

// 获取所有海域
func (s *ShipCtl) GetArea(c *gin.Context) {
	s.db = models.Db
	var area []models.SalvageArea
	s.db.Find(&area)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "获取成功",
		"data": area,
	})
}

// 删除BargeShip
func (s *ShipCtl) DeleteBargeShip(c *gin.Context) {
	s.db = models.Db
	id := c.Query("id")
	s.db.Delete(&models.BargeShip{}, id)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "删除成功",
	})
}

// 删除FisherShip
func (s *ShipCtl) DeleteFisherShip(c *gin.Context) {
	s.db = models.Db
	id := c.Query("id")
	s.db.Delete(&models.FisherShip{}, id)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "删除成功",
	})
}

// 添加BargeShip
func (s *ShipCtl) AddBargeShip(c *gin.Context) {
	s.db = models.Db
	var bargeShip models.BargeShip
	_ = c.ShouldBind(&bargeShip)
	s.db.Create(&bargeShip)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}

// 添加FisherShip
func (s *ShipCtl) AddFisherShip(c *gin.Context) {
	s.db = models.Db
	var fisherShip models.FisherShip
	_ = c.ShouldBind(&fisherShip)
	s.db.Create(&fisherShip)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}

// 删除用户
func (s *ShipCtl) DeleteUser(c *gin.Context) {
	s.db = models.Db
	id := c.Query("id")
	s.db.Delete(&models.User{}, id)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "删除成功",
	})
}

// 获取所有用户
func (s *ShipCtl) GetUser(c *gin.Context) {
	s.db = models.Db
	var user []models.User
	s.db.Find(&user)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "获取成功",
		"data": user,
	})
}

// 添加用户
func (s *ShipCtl) AddUser(c *gin.Context) {
	s.db = models.Db
	var user models.User
	_ = c.ShouldBind(&user)
	s.db.Create(&user)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}

// 编辑用户
func (s *ShipCtl) EditUser(c *gin.Context) {
	s.db = models.Db
	var user models.User
	_ = c.ShouldBind(&user)
	s.db.Save(&user)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "编辑成功",
	})
}
